import java.util.Scanner;

/**
 * @author : niu niu
 * @version : 1.0.0
 * @date : 2022/10/14 16:48
 * //计算糖果
 * //进制转换
 */
public class Day4 {
    //计算糖果
    public static void main1(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[] arr = new int[4];
        for (int i = 0; i < 4; i++) {
            arr[i] = scanner.nextInt();
        }
        //        暴力循环
//        for (int A = 0; A <= 30; A++) {
//            for (int B = 0; B <= 30; B++) {
//                for (int C = 0; C <= 30 ; C++) {
//                    if(A-B == arr[0] && B-C==arr[1] && A+B == arr[2] && B+C == arr[3]){
//                        System.out.println(A+" "+ B +" "+C);
//                        return;
//                    }
//                }
//            }
//        }
//        System.out.println("No");
        //数学思维
        int A = (arr[0] + arr[2]) / 2;
        int B = (arr[1] + arr[3]) / 2;
        int C = (arr[3]) - B;
        if ((A - B) == arr[0] && (B - C) == arr[1] && (A + B) == arr[2] && (B + C) == arr[3]) {
            System.out.println(A + " " + B + " " + C);
        } else {
            System.out.println("No");
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int M = scanner.nextInt();
        int N = scanner.nextInt();
        if (M == 0) {
            System.out.println("0");
        }
        char[] nums = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
        StringBuilder sb = new StringBuilder();
        boolean flag = M < 0;//判断正负
        M = Math.abs(M); //去绝对值
        while (M > 0) {
            sb.append(nums[M % N]);
            M /= N;
        }
        String res = sb.reverse().toString();
        if (flag){
            System.out.println("-"+res);
        }else {
            System.out.println(res);
        }
    }
}
